<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>共享文件桶</title>
    <link rel="icon" type="shortcut icon" th:href="@{/assets/img/favicon.ico}"/>
    <link rel="stylesheet" th:href="@{/assets/modules/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/assets/modules/dtree/dtree.css}">
    <link rel="stylesheet" th:href="@{/assets/modules/dtree/font/dtreefont.css}">
    <link rel="stylesheet" th:href="@{/assets/css/common.css}">
</head>

<body>

<div class="header">
    <div class="layui-container">
        <div class="layui-logo">
            <cite><div class="layui-hide-xs"><img th:src="@{/assets/img/logo.png}"/>共享文件桶</div></cite>
        </div>
    </div>

    <ul class="layui-nav layui-layout-right">

        <li class="layui-nav-item layui-hide-xs" lay-unselect>
            <a href="javascript:void(0)" id="fullScreen" title="全屏"><i
                    class="layui-icon layui-icon-screen-full"></i></a>
        </li>
        <li class="layui-nav-item" lay-unselect>
            <a style="margin-right: 10px;">
                <cite th:utext="${loginUser.nickname}"/>
            </a>
            <dl class="layui-nav-child">
                <dd lay-unselect><a href="javascript:void(0)" id="logout" data-url="/logout"><i
                        class="layui-icon layui-icon-logout"></i>退出</a>
                </dd>
            </dl>
        </li>
    </ul>
</div>

<div class="layui-container" style="padding-top: 15px;">
    <div class="layui-card">
        <div class="layui-card-header">
            <!--            <button class="layui-btn layui-btn-sm" onclick="modifyRoot()">选择根目录</button>-->
            当前位置：<span style="color:#1e9fff;"> <cite th:utext="${loginUser.root}"/></span>
        </div>
        <div class="layui-card-body">
            <div class="layui-row">
                <div class="layui-col-xs12" style="border: 3px solid #9f9f9f; height: 600px;">
                    <div style="padding: 5px 10px;">共享文件夹</div>

                    <table class="layui-hide" id="sharedir_table" lay-filter="sharedir_table"></table>
                </div>
            </div>
        </div>

    </div>
</div>


<div class="layui-footer layui-text">
    copyright © 2024 zhangrui.i all rights reserved.
</div>

<div id="layer-wrapper" style="display: none;">
    <div style="padding: 20px;font-size: 20px;">
        <span id="share_url"></span>
        <div style="padding: 16px 0;text-align: center;">
            <button class="layui-btn" onclick="copyText()">复制</button>
        </div>
    </div>
    <script type="text/javascript" th:src="@{/assets/modules/layui/layui.js}"></script>
    <script>
        var layer;
        layui.use(function () {
            layer = layui.layer;
        });

        function copyText() {
            // 获取要复制的文本内容
            var textToCopy = document.getElementById('share_url').innerText;
            // 创建一个临时的textarea元素并设置文本内容
            var tempTextArea = document.createElement("textarea");
            tempTextArea.value = "共享文件夹地址: " + textToCopy + "\n" +
                "\n" +
                "注意: 请完成账号注册后进行文件上传等操作!";
            // 将临时的textarea元素添加到页面中
            document.body.appendChild(tempTextArea);
            // 选中文本
            tempTextArea.select();
            // 尝试复制文本到剪切板
            var successful = document.execCommand('copy');
            // 移除临时的textarea元素
            document.body.removeChild(tempTextArea);
            // 提示用户复制是否成功
            if (successful) {
                layer.msg('共享链接已成功复制到剪切板！', {icon: 1});
            } else {
                layer.msg('复制失败，请手动复制文本！', {icon: 5});
            }
        }
    </script>
</div>

<script type="text/html" id="barDemo">
    <div class="layui-clear-space">
        <a class="layui-btn layui-btn-xs layui-bg-blue" lay-event="open">查看</a>
        <a class="layui-btn layui-btn-xs" lay-event="share">共享</a>
        <a class="layui-btn layui-btn-xs layui-bg-red" lay-event="delete">删除</a>

        <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="package">打包</a>
    </div>
</script>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="create">创建共享文件夹</button>
    </div>
</script>

<script type="text/javascript" th:src="@{/assets/modules/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/assets/modules/clipboard.min.js}"></script>
<script type="text/javascript" th:src="@{/assets/js/shareDir.js}"></script>
<script type="text/javascript" th:src="@{/assets/js/common.js}"></script>
<script type="text/javascript" th:src="@{/assets/modules/js-base64/base64.js}"></script>
<script>
    async function modifyRoot() {
        try {
            const directoryHandle = await window.showDirectoryPicker();
            const directoryPath = directoryHandle.name;
            // 获取文件夹路径
            console.log("选择的文件夹路径：" + directoryPath);
        } catch (err) {
            console.error("选择文件夹时出错：", err);
        }
    }
</script>
</body>
</html>
